package com.youlu.campus.website.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.website.common.enums.PlatformType;
import com.youlu.campus.website.entity.ActivityDescription;
import com.youlu.campus.website.entity.ActivityDescriptionPageQuery;
import com.youlu.campus.website.service.ActivityDescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 活动信息管理控制器
 */
@RestController
@RequestMapping("/api/activitiy")
public class ActivityDescriptionController {

    @Autowired
    private ActivityDescriptionService activityService;

    /**
     * 根据 id 查询活动
     *
     * @param id 活动主键
     * @return 活动对象或 404 响应
     */
    @GetMapping("/info")
    public QResult<ActivityDescription> getActivityById(@RequestParam String id) {
        ActivityDescription activity = activityService.getActivityById(id);
        return QResult.success(activity);
    }

    /**
     * 根据type 获取分页活动列表
     *
     * @return 所有活动列表
     */
    @PostMapping("/list-page")
    public QResult<Page<ActivityDescription>> findByPage(@RequestHeader("platform") PlatformType platform, @RequestBody ActivityDescriptionPageQuery pageQuery) {
        pageQuery.setEnabled(true);
        pageQuery.setPlatform(platform);
        Page<ActivityDescription> page = activityService.findByPageToWeb(pageQuery);
        return QResult.success(page);
    }

}